package com.chookss.video

import android.text.TextUtils
import android.view.View
import com.chookss.video.util.VideoUtils
import com.johnrambo.ktea.ktExtends.observe
import errorToast

/**
 * Company:
 * Project:
 * Author: liuhaoge
 * Date: 2021/1/20 16:17
 * Note:
 */
class VideoCatesPlayActivity : BaseVideoPlayActivity() {
    private var type:Int=0
    private val videoCate by lazy {
        intent?.getStringExtra("videoCate")
    }
    private var pageNum = 0

    override fun initOnCreate(): Boolean {
        return !TextUtils.isEmpty(videoCate)
    }

    override fun initVideoPlayView() {
        super.initVideoPlayView()
        type=intent.getIntExtra("type",0)
        videoPlayView.videoAdapter.setOnUpdateHolder { holder, position, entity ->
            holder.tvSetsInfo.visibility = View.GONE
            if(type==1){
                holder.tvMmarquee.visibility = View.VISIBLE
            }else{
                holder.tvMmarquee.visibility = View.GONE
            }
        }
    }

    override fun loadPlayList(isLoadMoreData: Boolean) {
        if (!isLoadMoreData) {
            this.pageNum = 0
        }
        var pageSize = 10
            videoModel!!.selectVideoByCatalogCode(videoCate!!, pageNum, pageSize).observe(this, {
                if (it.error != null) {
                    if (videoPlayView != null) {
                        videoPlayView.loadFailure()
                    }
                    errorToast(it.error?.message ?: "其他错误")
                } else {
                    pageNum++
                    var videoList = it.data!!.map { VideoUtils.videoEntityToModel(it) }
                    if (!isLoadMoreData) {
                        videoPlayView.refreshVideoList(videoList, videoList.size < pageSize)
                    } else {
                        videoPlayView.addMoreData(videoList, videoList.size < pageSize)
                    }
                }
            })

    }

    override fun initData() {
    }

}